package com.app.base.adapter;

import com.app.base.adapter.holder.BaseHolder;

import android.view.View;
import android.view.View.OnClickListener;


/**
 *可以处理item的点击事件
 *
 * @param <T>
 */
public class BaseClickRecyclerAdapter<T> extends BaseRecyclerViewAdapter<T> implements OnClickListener{

	
	public interface OnRecyclerViewItemClickListener {
		void onItemClick(View view, int position);
	}
	protected OnRecyclerViewItemClickListener mOnItemClickListener = null;
	public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
		this.mOnItemClickListener = listener;
	}
	
	public BaseClickRecyclerAdapter(int viewRes,
			Class<? extends BaseHolder<T>> holderClazz) {
		 super(viewRes, holderClazz);
		 setHasStableIds(true);
	}

	
	@Override
	public void onBindViewHolder(BaseHolder<T> viewHolder, int position) {
		super.onBindViewHolder(viewHolder, position);
		viewHolder.getRootView().setOnClickListener(this);
	}
	
	@Override
	public void onClick(View v) {
		if (mOnItemClickListener != null) {
			int position = (int) v.getTag();
            mOnItemClickListener.onItemClick(v,position);
        }
	}
}
